<style>
    .layuimini-container .deal-status:hover {
        border-color: #FFFFFF;
        color: #333;
    }
</style>
<div class="layuimini-container">
    <div class="layuimini-main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="batch_deal"> 批量处理</button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除</button>
            </div>
        </script>

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">留言标题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">留言内容</label>
                            <div class="layui-input-inline">
                                <input type="text" name="content" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">处理状态</label>
                            <div class="layui-input-inline">
                                <select name="is_deal">
                                    <option value="">选择处理状态</option>
                                    {foreach [0=>"未处理",1=>"已处理"] as $k=>$vo}
                                    <option value="{$k}">{$vo}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>


        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">

            {{#  if(d.is_deal === 0){ }}
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="deal">处理</a>
            {{#  } else { }}
            <a class="layui-btn layui-btn-primary layui-btn-xs deal-status">已处理</a>
            {{#  } }}
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>

            <a class="layui-btn layui-btn-xs" lay-event="edit">详情</a>

        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '{:url("message/index")}',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox"},
                {field: 'id', width: 80, title: 'ID'},
                {field: 'title', width: 160, title: '留言标题'},
                {field: 'user_name', minWidth: 120, title: '留言用户'},
                {field: 'user_mobile', minWidth: 120, title: '留言手机'},
                {field: 'content',minWidth: 180 ,title: '留言内容'},
                {
                    field: 'is_deal', title: '处理情况', width: 100, templet: function (d) {
                        if (d.is_deal == 1) {
                            return '<span style="color:#009688;">已处理</span>';
                        } else {
                            return '<span style="color: #FF5722;">未处理</span>';
                        }
                    }
                },
                {title: '操作', width: 200, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var event = obj.event;
            if (event === 'add') {  // 监听添加操作
                openDetail('新增', '{:url("message/add")}');
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i]['id']);
                }
                delItem('{:url("message/del")}', ids);
            }else if (obj.event === 'batch_deal') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i]['id']);
                }
                delItem('{:url("message/batch_deal")}', ids,"确认批量处理吗?");
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') {
                var url = '{:url("message/edit",["id"=>"ID"])}';
                url = url.replace("ID", data.id);
                openDetail('修改', url);
            } else if (layEvent === 'delete') {
                delItem('{:url("message/del")}', data.id);
            }else if (layEvent === 'deal') {
                delItem('{:url("message/batch_deal")}', data.id,"确定处理吗");
            }
        });

        form.on('submit(data-search-btn)', function (data) {
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');
            return false;
        });

    });
</script>